package myservice.android.database;

import myservice.android.Global;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class SourceDatabase {
	
	private static SQLiteDatabase database = null;
	
	public static boolean openConnection(String path) {						
		
		Log.i(Global.TAG,"Connecting to the source database '"+path+"'...");	
		try {
			database = SQLiteDatabase.openDatabase(path, null, 0);
		} catch (Exception e) {
			Log.e(Global.TAG,e.getMessage());
			return false;
		}				
		
		return true;
		
	}				
	
	public static void closeConnection() {
		
		Log.i(Global.TAG,"Closing the source database connection...");
		try {
			database.close();
		} catch (Exception e) {
			Log.e(Global.TAG,e.getMessage());
		}
	}			
	
	public static void execSQL(String sql) {
		Log.d(Global.TAG,"SOURCE DATABASE: "+sql);
		database.execSQL(sql);
	}
	
	public static Cursor select(String sql) {
		Log.d(Global.TAG,"SOURCE DATABASE: "+sql);
		return database.rawQuery(sql, null);
	}				
	
}
